package dry.example.demo01;

import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;

/**
 * @author zc
 */
public class Main {

    public static void main(String[] args) {
        Set<String> set = getFields(B.class);
        System.out.println(set);
    }

    public static Set<String> getFields(Class<?> clazz) {
        Set<String> set = new HashSet<>();
        getFields(clazz, set);
        return set;
    }

    private static void getFields(Class<?> clazz, Set<String> set) {
        if (clazz != null) {
            Field[] fields = clazz.getDeclaredFields();
            for (Field field : fields) {
                set.add(field.getName());
            }
            getFields(clazz.getSuperclass(), set);
        }
    }

}
